﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Asomy.Controllers
{
    /// <summary>
    /// Interaction logic for MessagePopup.xaml
    /// </summary>
    public partial class MessagePopup : Window
    {
        /// <summary>
        /// Will be true if user clicked ze Green Button. Will be false if user closed the window in 
        /// any way except through green Button
        /// </summary>
        public bool _OKclicked = false;

        //TODO: Refactor into dictionary where string is the key
        public TextBox[] m_inputFields;

        public MessagePopup(string a_message)
        {
            InitializeComponent();
            x_message.Content = a_message;
        }
        public MessagePopup(string a_message, string a_button1, string a_button2)
            : this(a_message)
        {           
            x_ok.Content = a_button1;
            x_cancel.Content = a_button2;
        }

        /// <summary>
        /// Messagepopup with an input field
        /// </summary>        
        /// <param name="a_input">Doesn't matter either true or false goes</param>
        /*public MessagePopup(string a_message, string a_button1, string a_button2, bool a_yoyo)
            : this(a_message,a_button1,a_button2)
        {
            x_input.Visibility = Visibility.Visible;   
        }*/

        public MessagePopup(string a_message, string a_button, string a_button2, string[] a_inputFields)
            : this(a_message,a_button,a_button2)
        {
            m_inputFields = new TextBox[a_inputFields.Length];

            Thickness f_pos = x_message.Margin;
            
            for (int i = 0; i < a_inputFields.Length; i++)
			{
                f_pos.Top += 28;

                Label f_desc = new Label();
                f_desc.Content = a_inputFields[i] + " :";
                f_desc.VerticalAlignment = VerticalAlignment.Top;
                f_desc.Height = 28;
                f_desc.Margin = f_pos;
                f_desc.Foreground = new SolidColorBrush(Color.FromRgb(221, 221, 221));

                f_pos.Top += 28;

                m_inputFields[i] = new TextBox();
                m_inputFields[i].Margin = f_pos;
                m_inputFields[i].Height = 28;
                m_inputFields[i].VerticalAlignment = VerticalAlignment.Top;
                m_inputFields[i].Background = new SolidColorBrush(Color.FromArgb(0,0,0,0));
                m_inputFields[i].BorderBrush = new SolidColorBrush(Color.FromArgb(34,0,0,0));
                m_inputFields[i].Foreground = new SolidColorBrush(Color.FromRgb(238, 238, 238));
                m_inputFields[i].Name = a_inputFields[i];

                x_grid.Children.Add(f_desc);
                x_grid.Children.Add(m_inputFields[i]);                
			}

            this.Height = 131 + m_inputFields.Length * 56;    
            
        }

        public string GetInputData(string a_name)
        {
            foreach (TextBox box in m_inputFields)
            {
                if (box.Name == a_name)
                {
                    return box.Text;
                }
            }

            return "";
        }

        public void SetInputData(string a_name, string a_data)
        {
            foreach (TextBox box in m_inputFields)
            {
                if (box.Name == a_name)
                {
                    box.Text = a_data;
                }
            }
        }

        public void ChangeOkButton(string a_string)
        {
            x_ok.Content = a_string;
        }
        public void ChangeCancelButton(string a_string)
        {
            x_cancel.Content = a_string;
        }

        private void ok_btnClick(object sender, RoutedEventArgs e)
        {
            _OKclicked = true;
            this.Close();
        }
        private void cancel_btnClick(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            base.OnClosing(e);
        }

    }
}

